package chapter07

import scala.collection.mutable

object Demo07_MutableSet {
  def main(args: Array[String]): Unit = {
    //创建可变Set  会自动删除重复的元素
    val set1: mutable.Set[Int] = mutable.Set(1,2,3,4,5,5,5)
    println(set1)
    println("=================")

    //1.添加元素
    val set2 = set1 + 11
    println(set2)

    set1 += 111
    println(set1)

    set1.add(1111)
    println(set1)
    println("=====================")
    //2、删除元素
    set1 -= 1
    println(set1)

    //3、合并两个Set
    val set3 = mutable.Set(11,21,31,41,51,51,51)
    println(set1)
    println(set3)

    println("===============")
    val set4 = set1 ++ set3
    println(set1)
    println(set3)
    println(set4)

    //谁调用谁改变
    set1 ++= set3
    println(set1)  //Set(51, 31, 5, 2, 3, 111, 21, 4, 1111, 11, 41)
    println(set3)  //Set(51, 31, 21, 11, 41)
  }
}
